<?php
/**
 * Description of ArticleAction
 *
 * @author Alen
 * @since 1.0.0 2014-3-23 by sutroon
 */
class FinanceWithdrawalAction extends ApiAction {
    
    //put your code here
    public function  index(){
        $biz=new SoBizWithDrawal();
        $dataset=$biz->select_arrayset(''.$this->get_paging_sql(), '*');
        if(!$dataset) exit ();
        $count=$biz->select_value('', 'count(SerialNo)');
        echo '{"total":'.$count.',"rows":'.  json_encode($dataset).'}';
    }
    
    public function save(){
        $biz=new SoBizWithDrawal();
        $msg=$biz->save();
        echo $this->get_json_fmt_result($msg);
    }
    public function remove(){        
        $biz=new SoBizWithDrawal();
        $msg=$biz->remove();
        echo $this->get_json_fmt_result($msg);
    }
    public function read_one(){
        $biz=new SoBizWithDrawal();
        $id=request_numeric('id');
        $dataset=$biz->read_one($id);
        if($dataset){
            $arr=array('id'=>$id,'username'=>$dataset['UserName'],'frozenblance'=>$dataset['FrozenBlance'],'frozenblance'=>$dataset['FrozenBlance'],'state'=>$dataset['State']);
            echo json_encode($arr);
        }
    }
    public function set_state(){        
        $biz=new SoBizWithDrawal();
        $msg=$biz->update_records('State='.request_numeric('state'), 'ID='.request_numeric('id'));
        echo $this->get_json_fmt_result($msg);
    }
    public function read_summary(){        
        $biz=new SoBizWithDrawal();
        // 设置统计信息
        $blance_all=$biz->get_amount_all();
        $blance_confirmed=$biz->get_amount_confirmed();
        $blance_unconfirmed= $biz->get_amount_unconfirmed();
        echo sprintf('{"all":%d,"confirmed":%d,"unconfirmed":%d}',$blance_all,$blance_confirmed,$blance_unconfirmed);
    }
}
